import { h } from 'vue';
import { Tag, Avatar} from 'ant-design-vue';

export const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    fixed: 'left',
    width: 50,
  },
<#list table.fields as field>
<#if field.propertyName != 'id' 
  && field.propertyName != 'createUser' 
  && field.propertyName != 'createTime' 
  && field.propertyName != 'updateUser' 
  && field.propertyName != 'updateTime' 
  && field.propertyName != 'delFlag' 
  && field.propertyName != 'tenantId'
>
  <#if (field.customMap?? && field.customMap?size > 0)>
  <#if (field.customMap?size > 2)>
  {
    title: '${field.comment}',
    dataIndex: '${field.propertyName}',
    width: 100,
    customRender({ record }) {
      let ${field.propertyName}Text = '';
      switch (record.${field.propertyName}) {
      <#list field.customMap?keys as key>
        case ${key}:
          ${field.propertyName}Text = '${field.customMap[key]!}';
          break;
      </#list>
        default:
          break;
      }
      return h('span', ${field.propertyName}Text || '-');
    },
  },
  <#else>
  {
    title: '${field.comment}',
    dataIndex: '${field.propertyName}',
    width: 100,
    customRender({ record }) {
      return h(
        Tag,
        {
          color: record.${field.propertyName} == ${field.metaInfo.defaultValue} ? 'success' : 'error',
        },
        {
          default: () => (record.${field.propertyName} == ${field.metaInfo.defaultValue} ? '${field.customMap["1"]!}' : '${field.customMap["2"]!}'),
        },
      );
    },
  },
  </#if>
  <#elseif field.propertyName == 'cover' || field.propertyName == 'logo' || field.propertyName == 'image'>
  {
    title: '${field.comment}',
    dataIndex: '${field.propertyName}',
    key: '${field.propertyName}',
    width: 80,
    customRender({ record }) {
      return h(Avatar, {
        size: 48,
        src: record.${field.propertyName},
        shape: 'square',
        fit: 'fill',
      });
    },
  },
  <#else>
  {
    title: '${field.comment}',
    dataIndex: '${field.propertyName}',
    width: 100,
  },
  </#if>
</#if>
</#list>
  {
    title: '创建人',
    dataIndex: 'createUser',
    width: 100,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: '操作',
    fixed: 'right',
    dataIndex: 'action',
    key: 'action',
    width: 200,
  },
];
